#include "xconfig_server.h"
#include <iostream>
#include <xplatform/XMsg.h>
#include <xplatform/XTools.h>
#include <xplatform/thread_pool/XThreadPool.h>
#include <register/register_client/xregister_client.h>
#include "xconfig_handle.h"
void XConfigServer::Main(int argc, char *argv[])
{
    XCOM_LOG_DEBUG("config_server register_ip register_port server_port"<<this);
    // 注册消息回调函数
    // 注册中心的配置
    std::string register_ip = "127.0.0.1";
    if (argc > 1)
    {
        register_ip = argv[1];
    }
    int register_port = REGISTER_PORT;
    if (argc > 2)
    {
        register_port = atoi(argv[2]);
    }
    int server_port = CONFIG_PORT;
    if (argc > 3)
    {
        server_port = atoi(argv[3]);
    }
    // 设置端口
    set_server_port_(server_port);
    XRegisterClient::Get()->MsgFuncCallback();
    XRegisterClient::Get()->setServerIP("127.0.0.1");
    XRegisterClient::Get()->setServerPort(register_port);
    // // 向注册中心注册
    XRegisterClient::Get()->RegisterServer(CONFIG_NAME, server_port, register_ip.c_str());
}

void XConfigServer::Wait()
{
    XThreadPool::Wait();
}

XServiceHandle *XConfigServer::CreateServiceHandle()
{
    return new XConfigServerHandle();
}